package be.sc.classicnetwork.view.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import be.sc.classicnetwork.exception.ApplicationException;
import be.sc.classicnetwork.model.Car;
import be.sc.classicnetwork.model.Option;

/**
 * CheckedTag.
 */
public class CheckedTag extends TagSupport {

    private static final long serialVersionUID = -4914317075977174592L;

    private Option option;

    /**
     * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
     */
    @Override
    public int doEndTag() throws JspException {
	Car car = (Car) pageContext.findAttribute("command");
	if (car.getOptions().contains(option)) {
	    try {
		pageContext.getOut().write("checked='checked'");
	    } catch (IOException e) {
		throw new ApplicationException(e);
	    }
	}
	return super.doEndTag();
    }

    public Option getOption() {
	return option;
    }

    public void setOption(Option option) {
	this.option = option;
    }
}
